/*
 * @ created for matlabMe by Leszek Piątek, 2009
 */
package variables;
import java.util.Vector;

public class Variables {
   //PRIVATE SECTION
    private static int maxVariables=5;
    private static Vector stackV=new Vector(maxVariables);
    private static Vector stackK=new Vector(maxVariables);
    private static int index=0;

   //PUBLIC SECTION
    public Variables() {
    }

    public void add(Object obj, String ID) {
        int i;
        boolean change=false;
        for (i=0; i<stackK.size();i++) {
            if(ID.equalsIgnoreCase((String)stackK.elementAt(i))) {
                change=true;
                break;
            }
        }

        if(!change) {
            stackV.insertElementAt(obj, index);
            stackK.insertElementAt(ID, index);
            index=(index+1)%maxVariables;
        } else {
            stackV.insertElementAt(obj, i);
            stackK.insertElementAt(ID, i);
        }
    }

    public Object get(String ID) throws Exception {
        int i;
        for (i=0; i<stackK.size();i++) {
            if(ID.equalsIgnoreCase((String)stackK.elementAt(i)))
                return stackV.elementAt(i);
        }
        throw new Exception("There is no variable with ID '"+ID+"'\n");
    }

     public Object get(int i) {
        return stackV.elementAt(i);
     }

     public String getId(int i) {
        return (String)stackK.elementAt(i);
     }

    public int size() {
        return stackV.size();
    }
}